/**
 * Initialize your data structure here.
 */
var MyQueue = function () {
  this.stackPush = []
  this.stackPop = []
}

/**
 * Push element x to the back of queue.
 * @param {number} x
 * @return {void}
 */
MyQueue.prototype.push = function (x) {
  this.stackPush.push(x)
}

MyQueue.prototype.clear = function () {
  if (this.empty()) {
    return
  }
  if (!this.stackPop.length) {
    while (this.stackPush.length) {
      this.stackPop.push(this.stackPush.pop())
    }
  }
}

/**
 * Removes the element from in front of queue and returns that element.
 * @return {number}
 */
MyQueue.prototype.pop = function () {
  if (this.empty()) {
    throw new Error('queue is empty')
  }
  this.clear()
  return this.stackPop.pop()
}

/**
 * Get the front element.
 * @return {number}
 */
MyQueue.prototype.peek = function () {
  this.clear()
  return this.stackPop[this.stackPop.length - 1]
}

/**
 * Returns whether the queue is empty.
 * @return {boolean}
 */
MyQueue.prototype.empty = function () {
  return this.stackPush.length === 0 && this.stackPop.length === 0
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */
